<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>养一只美短</title>
</head>
<body>
    <ul>
        <li>养一只美短</li>
        <li>养两只美短</li>
        <li>养三只美短</li>
        <li>养四只美短</li>
        <li>养五只美短</li>
        <li>养六只美短</li>
        <li>养七只美短</li>
        <li>养八只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
        <li>养九只美短</li>
       
        
    </ul>
    <script>
        const list = document.querySelectorAll('ul li')
        for (let i = 0; i < list.length; i++) {
            const element = list[i]
            element.onclick = function(){
                this.style.backgroundColor = 'red'
                this.style.color = 'white'
            }
        }
    </script>
</body>
</html>